/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.Configuration.world;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.tygzs.minerpg.Main;
import org.bukkit.Bukkit;
import org.bukkit.World;

/**
 *
 * @author thtTNT
 */
public class WorldConfig
{

    private final Map<Integer, WorldInfo> defaultConfig = new HashMap<>();
    private final Map<String, Map<Integer, WorldInfo>> worldConfig = new HashMap<>();
    private boolean isDrop = false;

    public WorldConfig()
    {
        this.isDrop = Main.getPlugin().getConfig().getBoolean("World.Drop");
        this.defaultConfig.put(0, new WorldInfo());
        this.defaultConfig.get(0).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.Default"));
        for (int vip = 1; vip <= Main.getPlugin().getConfig().getInt("server.MaxVip"); vip++)
        {
            this.defaultConfig.put(vip, new WorldInfo());
            if (Main.getPlugin().getConfig().contains("World.Default.OddsOfDrop.VIP" + vip))
            {
                this.defaultConfig.get(vip).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.VIP" + vip));
            } else
            {
                this.defaultConfig.get(vip).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.Default"));
            }
        }
        List<World> worlds = Bukkit.getWorlds();
        for (World world : worlds)
        {
            String name = world.getName();
            if (Main.getPlugin().getConfig().contains("World." + name))
            {
                this.worldConfig.put(name, new HashMap<Integer, WorldInfo>());
                this.worldConfig.get(name).put(0, new WorldInfo());
                this.worldConfig.get(name).get(0).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.Default"));
                for (int vip = 1; vip <= Main.getPlugin().getConfig().getInt("server.MaxVip"); vip++)
                {
                    this.worldConfig.get(name).put(vip, new WorldInfo());
                    if (Main.getPlugin().getConfig().contains("World.Default.OddsOfDrop.VIP" + vip))
                    {
                        this.worldConfig.get(name).get(vip).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.VIP" + vip));
                    } else
                    {
                        this.worldConfig.get(name).get(vip).setOddsOfDrop(Main.getPlugin().getConfig().getDouble("World.Default.OddsOfDrop.Default"));
                    }
                }
            }
        }
    }

    public WorldInfo getDefaultWorldInfo(int vip)
    {
        return this.defaultConfig.get(vip);
    }

    public WorldInfo getWorldInfo(String world, int vip)
    {
        if (this.worldConfig.containsKey(world))
        {
            return this.worldConfig.get(world).get(vip);
        } else
        {
            return null;
        }
    }

    /**
     * @return the isDrop
     */
    public boolean isIsDrop()
    {
        return isDrop;
    }

    /**
     * @param isDrop the isDrop to set
     */
    public void setIsDrop(boolean isDrop)
    {
        this.isDrop = isDrop;
    }
}
